package com.example.demo.controller;

import com.example.demo.entity.common.PageParams;
import com.example.demo.entity.common.PageResult;
import com.example.demo.entity.common.AppResp;
import com.example.demo.entity.vo.DemoVO;
import com.example.demo.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * Demo 控制层
 * </p>
 *
 * @author javalaoniu
 * @since 2022-03-25
 */
@Api(tags = "Demo相关接口")
@Validated
@RestController("demoController4demo")
@RequestMapping("/test/demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @ApiOperation(value = "查询列表分页")
    @PostMapping("/page")
    public AppResp<PageResult<DemoVO>> page(@RequestBody PageParams<DemoVO> pageParams){
        return demoService.page(pageParams);
    }

    @ApiOperation(value = "根据记录Id查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "demoId", value = "记录id", required = true)
    })
    @GetMapping("")
    public AppResp<DemoVO> queryById(@RequestParam Long demoId){
        return demoService.queryById(demoId);
    }

    @ApiOperation(value = "添加记录")
    @PostMapping("")
    public AppResp<Void> add(@Validated DemoVO demoVO){
        return demoService.add(demoVO);
    }

    @ApiOperation(value = "删除记录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "demoId", value = "记录id", required = true)
    })
    @DeleteMapping("")
    public AppResp<Void> delById(@RequestParam Long demoId){
        return demoService.delById(demoId);
    }

    @ApiOperation(value = "修改记录")
    @PutMapping("")
    public AppResp<Void> modify(@Validated DemoVO demoVO){
        return demoService.modify(demoVO);
    }
}